<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link type="text/css" rel="stylesheet" href="/css/style.css">
<link type="text/css" rel="stylesheet" href="/js/font-awesome-4.7.0/css/font-awesome.css">
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<title>注册信息</title>
</head>
<body>
	<div class="container">
		<table class="table" id="plantTable">
			<tr>
				<td colspan="13" align="center">投资名称<input type="text" id="name">投资金额<input type="text" id="minAmount">&nbsp; - &nbsp;<input type="text" id="maxAmount">
					<button class="btn btn-primary" id="searchBtn">搜索</button>&nbsp;&nbsp;&nbsp;<button class="btn btn-primary" id="addBtn">添加</button>
				</td>
			</tr>

			<tr>
				<th align="center"><input type="checkbox" id="select-all">全选</th>
				<th>序号</th>
				<th>计划名称</th>
				<th>投资金额</th>
				<th>项目经理</th>
				<th>投资说明</th>
				<th>部门名称</th>
				<th>操作</th>
			</tr>
			<c:forEach items="${investInfoPages.records }" var="invests">
				<tr>
					<td align="center"><input type="checkbox" class="checkInvestId" value="${invests.id }" /></td>
					<td>${invests.id }</td>
					<td>${invests.name }</td>
					<td>${invests.amount }</td>
					<td>${invests.manager }</td>
					<td>${invests.content }</td>
					<td>${invests.deptName }</td>
					<td><a href="/showInvestInfo?id=${invests.id }">查看</a>&nbsp;<a href="/showInvest?id=${invests.id }">修改</a>&nbsp;<a href="/remove?id=${invests.id}">删除</a></td>
				</tr>
			</c:forEach>
			<tr>
				<td align="center"><button type="button" id="batchRemoveBtn">批量删除</button></td>
				<td colspan="12" align="center"><button type="button" id="firstBtn">首页</button>
					<button type="button" id="previousBtn">上一页</button> 
					<%-- <c:forEach begin="1" end="${pages }" var="pageNo">
						${pageNo }
					</c:forEach> --%>
					<button type="button" id="nextBtn">下一页</button>
					<button type="button" id="lastBtn">末页</button> &nbsp;&nbsp;当前是第${currentPage}页/共计${pages }页</td>
			</tr>
		</table>
	</div>
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
	<script type="text/javascript">
		$(function() {
			$('#searchBtn').click(function() {
				var name = $('#name').val();
				var minAmount = $('#minAmount').val();
				var maxAmount = $('#maxAmount').val();
				location = "/?name=" + name + "&minAmount=" + minAmount + "&maxAmount=" + maxAmount;
			})
			// 全选
			$('#select-all').click(function() {
				if ($(this).is(":checked")) {
					$('.checkInvestId').prop("checked", true)
				} else {
					$('.checkInvestId').prop("checked", false)
				}
			})
			// 批量删除
			$('#batchRemoveBtn').click(function() {
				var checkedInfoList = $('.checkInvestId:checked');
				if (checkedInfoList.length == 0) {
					alert("请选择要删除的注册信息")
				} else {
					var removeUrl = "/remove?"
						checkedInfoList.each(function() {
							var id = $(this).val();
							removeUrl += "id=" + id + "&"
						})
						removeUrl = removeUrl.substring(0, removeUrl.length - 1);
						location = removeUrl;
					}
			})
		})
		//首页
		$('#firstBtn').click(function() {
			location = "/?pageNo=1";
		})
		//上一页
		$('#previousBtn').click(function() {
			var current = ${currentPage};
			if (current > 1) {
				location = "/?pageNo=" + (current - 1);
			} else {
				location = "/?pageNo=1";
			}
		})
		//下一页
		$('#nextBtn').click(function() {
			var current = ${currentPage};
			var last = ${pages};
			if (last == current) {
				location = "/?pageNo=" + last;
			} else if (last == 1) {
				location = "/?pageNo=1";
			} else if (last > current) {
				location = "/?pageNo=" + (current + 1);
			}
		})
		//末页
		$('#lastBtn').click(function() {
			location = "/?pageNo=" + ${pages};
		})
		$('#addBtn').click(function(){
			location = "/addInvest";
		})
	</script>
</body>
</html>